package com.cr.manager.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.cr.manager.domain.dto.RentDto;
import com.cr.manager.domain.vo.RentVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cr.common.annotation.Log;
import com.cr.common.core.controller.BaseController;
import com.cr.common.core.domain.AjaxResult;
import com.cr.common.enums.BusinessType;
import com.cr.manager.domain.Rent;
import com.cr.manager.service.IRentService;
import com.cr.common.utils.poi.ExcelUtil;
import com.cr.common.core.page.TableDataInfo;

/**
 * 租借管理Controller
 * 
 * @author lms
 * @date 2024-08-07
 */
@RestController
@RequestMapping("/manager/rent")
public class RentController extends BaseController
{
    @Autowired
    private IRentService rentService;

    /**
     * 查询租借管理列表
     */
    @PreAuthorize("@ss.hasPermi('manager:rent:list')")
    @GetMapping("/list")
    public TableDataInfo list(RentDto rentDto)
    {
        startPage();
        List<RentDto> list = rentService.selectRentList(rentDto);
        return getDataTable(list);
    }

    /**
     * 导出租借管理列表
     */
    @PreAuthorize("@ss.hasPermi('manager:rent:export')")
    @Log(title = "租借管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RentDto rentDto)
    {
        List<RentDto> list = rentService.selectRentList(rentDto);
        ExcelUtil<RentDto> util = new ExcelUtil<RentDto>(RentDto.class);
        util.exportExcel(response, list, "租借管理数据");
    }

    /**
     * 获取租借管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('manager:rent:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(rentService.selectRentById(id));
    }

    /**
     * 新增租借管理
     */
    @PreAuthorize("@ss.hasPermi('manager:rent:add')")
    @Log(title = "租借管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RentVo rentVo)
    {
        return toAjax(rentService.insertRent(rentVo));
    }

    /**
     * 修改租借管理
     */
    @PreAuthorize("@ss.hasPermi('manager:rent:edit')")
    @Log(title = "租借管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Rent rent)
    {
        return toAjax(rentService.updateRent(rent));
    }

    /**
     * 删除租借管理
     */
    @PreAuthorize("@ss.hasPermi('manager:rent:remove')")
    @Log(title = "租借管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable String id)
    {
        return toAjax(rentService.deleteRentById(id));
    }
}
